<template>
  <div class="my-mistake">
    <div :class="['header-top', scroll > 0 ? 'active' : '']">
      <div class="header_left" @click="$router.back()">
        <van-icon name="arrow-left" style="margin-left:.2rem;" />
      </div>
      <div class="center_title">{{ title }}</div>
      <div class="header_right"></div>
    </div>
    <div class="fixed-box"></div>
    <div class="mistake-content">
      <div class="wrong-count">
        <p class="number">{{ wrongTotalNum }}</p>
        <p class="title">总错题</p>
      </div>
      <div class="review-btn" @click="toPath('review')">错题回顾</div>
      <div class="follow-up" @click="toPath('wrong')">错题随练</div>
      <van-circle
        class="circle"
        v-model="currentRate"
        color="#fff"
        size="2.496rem"
        stroke-width="44"
        layer-color="transparent"
        fill="transparent"
        :rate="rate"
        :speed="100"
      />
    </div>
    <div class="wrong-again-test" v-if="false">
      <div class="wrong-title">错题重练</div>
      <ul class="wrong-menu">
        <li
          :class="['menu-item', menuType === 'chapter' ? 'active' : '']"
          @click="menuHandle('chapter')"
        >
          章节练习
        </li>
        <li
          :class="['menu-item', menuType === 'special' ? 'active' : '']"
          @click="menuHandle('special')"
        >
          专项训练
        </li>
        <li
          :class="['menu-item', menuType === 'test' ? 'active' : '']"
          @click="menuHandle('test')"
        >
          考试练习
        </li>
      </ul>
      <ul class="content-list">
        <li class="list-item">
          <div class="item_left">第一章 马克思主义基本原理概论</div>
          <div class="item_right">
            <div>1</div>
            <img class="right_icon" src="/img/mobile/right-icon.png" alt="" />
          </div>
        </li>
        <li class="list-item">
          <div class="item_left">第二章 马克思主义基本原理概论</div>
          <div class="item_right">
            <div>1</div>
            <img class="right_icon" src="/img/mobile/right-icon.png" alt="" />
          </div>
        </li>
        <li class="list-item">
          <div class="item_left">第三章 马克思主义基本原理概论</div>
          <div class="item_right">
            <span>4</span>
            <img class="right_icon" src="/img/mobile/right-icon.png" alt="" />
          </div>
        </li>
        <li class="list-item">
          <div class="item_left">第四章 马克思主义基本原理概论</div>
          <div class="item_right">
            <span>4</span>
            <img class="right_icon" src="/img/mobile/right-icon.png" alt="" />
          </div>
        </li>
        <li class="list-item">
          <div class="item_left">第五章 马克思主义基本原理概论</div>
          <div class="item_right">
            <span>4</span>
            <img class="right_icon" src="/img/mobile/right-icon.png" alt="" />
          </div>
        </li>
      </ul>
    </div>
  </div>
</template>

<script>
import { mapState, mapActions, mapMutations } from "vuex";
import {
  getQuestionBankWrongTotal,
  getQuestionBankWrong,
  getExamWrong,
  getSpecWrong
} from "~/api/v2-question-bank/question-bank.js";
export default {
  components: {},
  data() {
    return {
      title: "我的错题",
      scroll: 0,
      currentRate: 0,
      rate: 30,
      menuType: "chapter",
      wrongTotalNum: 0
    };
  },
  computed: {
    ...mapState({
      user_info(state) {
        return state.user_info;
      },
      is_loading(state) {
        return state.is_loading;
      }
    }),
    /* 题套Id */
    questionId() {
      return this.$route.query.id;
    }
  },
  watch: {},
  methods: {
    ...mapMutations(["SET_IS_LOADING"]),
    menuHandle(type) {
      this.menuType = type;
    },
    toPath(type) {
      let params = { path: "/m/v2-answer-sheet" };
      if (type == "wrong") {
        params = {
          ...params,
          query: {
            id: this.questionId,
            type: 4
          }
        };
      } else if (type == "review") {
        params = {
          ...params,
          query: {
            id: this.questionId,
            type: 4,
            review: 1
          }
        };
      }
      this.$router.push(params);
    },
    /* 获取错题总量 */
    async getWrongNum() {
      this.SET_IS_LOADING(true);
      let result = await getQuestionBankWrongTotal({
        questionGroupId: this.questionId,
        userId: this.user_info.id
      });
      console.log("获取错题总量：", result);
      if (result && result.data && result.data.code == 200) {
        const { data } = result.data;
        this.wrongTotalNum = data;
        this.SET_IS_LOADING(false);
      } else {
        this.SET_IS_LOADING(false);
      }
    },
    /* 获取错题 */
    async getQuestionBankWrong() {
      this.SET_IS_LOADING(true);
      let params = {
        userId: this.user_info.id
      };
      let result = await getQuestionBankWrong(params);
      console.log("获取错题：", result);
      if (result && result.data && result.data.code == 200) {
      }
      this.SET_IS_LOADING(false);
    },
    /*  获取专项训练错题 */
    async getSpecWrong() {
      this.SET_IS_LOADING(true);
      let params = {
        userId: this.user_info.id
      };
      let result = await getSpecWrong(params);
      console.log("获取专项训练错题：", result);
      if (result && result.data && result.data.code == 200) {
      }
      this.SET_IS_LOADING(false);
    },
    /*  获取考试练习错题 */
    async getExamWrong() {
      this.SET_IS_LOADING(true);
      let params = {
        userId: this.user_info.id
      };
      let result = await getExamWrong(params);
      console.log("获取考试练习错题：", result);
      if (result && result.data && result.data.code == 200) {
      }
      this.SET_IS_LOADING(false);
    },
    initPage() {
      this.getWrongNum();
      this.getQuestionBankWrong();
      // this.getSpecWrong();
      // this.getExamWrong();
    }
  },
  created() {
    this.initPage();
  },
  activated() {
    this.initPage();
  },
  mounted() {}
};
</script>

<style lang="scss" scoped>
.my-mistake {
  background-color: #f7f7fa;
  min-height: 100vh;
  width: 7.2rem;
  .header-top {
    background: var(--theme-color);
    width: 7.2rem;
    height: 0.9rem;
    z-index: 999999;
    position: fixed;
    top: 0;
    left: 0;
    line-height: 0.9rem;
    display: flex;
    align-items: center;
    box-shadow: none;
    .header_left {
      width: 15%;
      color: #ffffff;
      font-size: 0.35rem;
      display: flex;
      align-items: center;
    }
    .center_title {
      width: 70%;
      text-align: center;
      font-size: 0.3456rem;
      color: #ffffff;
      // font-weight: bold;
    }
    .header_right {
      width: 15%;
      img {
        margin: 0 auto;
        display: block;
        width: 0.6111rem;
        height: 0.6111rem;
      }
    }
  }
  .header-top.active {
    background: var(--theme-color);
  }
  .fixed-box {
    width: 100%;
    height: 0.9rem;
  }
  .mistake-content {
    width: 7.2rem;
    height: 5.568rem;
    background-image: url("/img/mobile/my-mistake-bg.png");
    background-repeat: no-repeat;
    background-size: 100% 100%;
    background-color: var(--theme-color);
    position: relative;
    .circle {
      position: absolute;
      // left: 1.1712rem;
      left: 49.5%;
      transform: translateX(-50%);
      top: 0.4416rem;
    }
    .wrong-count {
      position: absolute;
      left: 50%;
      transform: translateX(-50%);
      top: 1rem;
      color: #ffffff;
      text-align: center;
      .number {
        font-size: 0.864rem;
      }
      .title {
        font-size: 0.2496rem;
        letter-spacing: 0.02rem;
      }
    }
    .review-btn,
    .follow-up {
      position: absolute;
      bottom: 0.7rem;
      width: 2.016rem;
      height: 0.8448rem;
      line-height: 0.8448rem;
      text-align: center;
      background-color: #ffffff;
      box-shadow: 0 0 0.384rem 0 rgba(71, 76, 85, 0.15);
      border-radius: 0.4224rem;
      font-size: 0.288rem;
      color: var(--theme-color);
    }
    .review-btn {
      left: 1.0752rem;
    }
    .follow-up {
      right: 1.0752rem;
    }
  }
  .wrong-again-test {
    width: 7.2rem;
    margin-top: 0.192rem;
    background-color: #ffffff;
    .wrong-title {
      font-size: 0.3072rem;
      font-weight: bold;
      color: #313233;
      padding: 0.288rem 0.288rem 0.1rem;
    }
    .wrong-menu {
      width: 7.2rem;
      height: 0.768rem;
      background-color: #ffffff;
      display: flex;
      justify-content: space-between;
      .menu-item {
        width: 33.3333%;
        height: 0.768rem;
        text-align: center;
        line-height: 0.768rem;
        font-size: 0.2688rem;
        font-weight: bold;
        position: relative;
        color: #949699;
        &.active {
          color: #313233;
        }
        &.active::after {
          content: "";
          display: block;
          position: absolute;
          left: 50%;
          bottom: 0;
          width: 0.576rem;
          height: 0.0384rem;
          transform: translateX(-50%);
          background-color: var(--theme-color);
        }
      }
    }
    .content-list {
      width: 7.2rem;
      background: #ffffff;
      padding-left: 0.288rem;
      padding-top: 0.2rem;
      padding-bottom: 0.2rem;
      box-sizing: border-box;
      .list-item {
        width: 100%;
        height: 1rem;
        border-bottom: 0.0096rem solid #ededf1;
        display: flex;
        align-items: center;
        justify-content: space-between;
        font-size: 0.2688rem;
        font-weight: bold;
        &:last-child {
          border-bottom: none;
        }
        .item_right {
          display: flex;
          align-items: center;
          // line-height: .2304rem;
          font-size: 0.288rem;
          .right_icon {
            margin: 0 0.2rem 0 0.2rem;
            width: 0.2304rem;
            height: 0.2304rem;
            display: block;
          }
        }
      }
    }
  }
}
</style>
